package WinterFlower.work0718;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * @author ZJM
 * @version 1.0
 * @since 2022-07-18 19:20:22
 */
public class LotteryTicket {

     public static void main(String[] args) {
         int [] selfNums = getNum1();
         int [] userNums = getNum2();
         System.out.println("抽奖人的号码:");

         for (int i : userNums) {
             System.out.print(i+"\t");
         }
         System.out.println();
         System.out.println("中奖的号码是：");
         for (int i : selfNums) {
             System.out.print(i+"\t");
         }
         System.out.println();
         if(getGrade(selfNums,userNums)){
             System.out.println("恭喜你获奖了");
         }else{
             System.out.println("非常遗憾没有获奖");
         }
         }



    public static int [] getNum1(){
         int [] nums = new int[7];//存放中奖彩票的号码
        Random random = new Random();//随机生成
        for (int i = 0; i <nums.length ; i++) {
            int num = random.nextInt(33)+1;

            boolean contain = find(num,nums);
            if(contain){
                i--;
            }else{
                nums[i] = num;
            }
        }
        return nums;
    }

    public static boolean find(int x,int[] nums){// 判断是否重复
        for (int i : nums) {
            if(i == x){
                return true;
            }
        }
        return false;
    }


    public static int[] getNum2(){//小明输入自己的抽奖号码
         int [] nums = new int[7];

         Scanner sc = new Scanner(System.in);
        for (int i = 0; i <nums.length ; i++) {
            int num = sc.nextInt();
            if(num <0 || num >33){
                i--;
            }else if(find(num,nums)){
                i--;
            }else{
                nums[i] = num;
            }
        }
        return nums;
    }

    public static boolean getGrade(int[] getNum1,int [] getNum2){
        Arrays.sort(getNum1);
        Arrays.sort(getNum2);

        for (int i = 0; i < getNum2.length  ; i++) {
            if(getNum1[i] != getNum2[i]){
                return false;
            }

        }
        return true;
    }


}
